package com.demo.service;



import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ChatService {
	
	
	@Autowired
	private WebSocket webSocket;
	
	/**
	 * 患者问诊
	 * @param user
	 * @param message
	 * @param respondent
	 * @return
	 */
	public String getMessageFromPatient(String user,String message,String respondent) {
		
		if(respondent.equals("AI")) {
			return byAI(user, message, respondent);
		}
		if(respondent.equals("AR")) {
			return byAR(user, message, respondent);
		}
		if(respondent.equals("otherApp")) {
			return byDoctor(user, message, respondent);
		}
		return null;
		
		
		
	}
	
	/**
	 * 智能导诊
	 * @param user
	 * @param message
	 * @param respondent
	 * @return
	 */
	public String byAI(String user,String message,String respondent) {
		
//		String[] answer= {"请问有什么可以帮您","请问您有什么症状","建议您多喝热水","建议您尽快来医院检查","稍后为您推荐医生请等待"};
//		Random random = new Random();
//		int num= random.nextInt(4 - 0 + 1) + 0;
//		
		String back = "";
		if(message.indexOf("你好")!=-1||message.indexOf("hi")!=-1||message.indexOf("哈喽")!=-1||
				message.indexOf("hello")!=-1||message.indexOf("您好")!=-1) {
				back="请描述一下您的问题，我们会耐心为你解答！";
		}else if(message.indexOf("痛")!=-1||
				message.indexOf("难受")!=-1||message.indexOf("不舒服")!=-1||message.indexOf("发烧")!=-1) {
				back="请清淡饮食，多喝热水，多运动，注意提防感冒！";
		}else if(message.indexOf("伤")!=-1||
				message.indexOf("断")!=-1||message.indexOf("吐")!=-1||message.indexOf("晕")!=-1) {
				back="似乎有点严重哦，请及时去医院找医生做个检查吧！";
		}else if(message.indexOf("怎么办")!=-1||
				message.indexOf("天啦")!=-1||message.indexOf("啊")!=-1||message.indexOf("奔溃")!=-1) {
				back="没有什么比医生当面诊断更快啦，快去挂号到医院就诊吧！";
		}else if(message.indexOf("好的")!=-1||message.indexOf("好吧")!=-1||message.indexOf("行")!=-1||
				message.indexOf("谢谢")!=-1) {
				back="请问还有别的问题吗？";
		}else if(message.indexOf("没有")!=-1||message.indexOf("无")!=-1||message.indexOf("不")!=-1) {
				back="感谢您使用智能就医平台,再见 !";
		}else if(message.indexOf("再见")!=-1||message.indexOf("bai")!=-1||message.indexOf("拜")!=-1
				||message.indexOf("bye")!=-1){
				back="链接即将断开，如有问题，请再次访问，谢谢！";
		}else {
			back = "不好意思，我有点听不懂唉，可能描述的再详细点吗？";
		}
		return back;
	}
	
	/**
	 * 人工导诊
	 * @param user
	 * @param message
	 * @param respondent
	 * @return
	 */
	public String byAR(String user,String message,String respondent) {
		webSocket.sendOneMessage("医生", message);
		
		return null;
	}
	
	/**
	 * 医生的回答
	 * @param user
	 * @param message
	 * @param respondent
	 * @return
	 */
	public String byDoctor(String user,String message,String respondent) {
		webSocket.sendOneMessage("person1", message);
		return null;
	}

}
